#define PrynGuiInternal
#define PrynGuiImplementation
#include <prynGui.h>
#include <pryn.h>
#include "../strings.h"

PrynGuiExport (PrynResult, prynGuiControlState, (PrynGuiControl *control, PrynState **output))
{
	if (output) *output = 0;
	if (!control) return PrynResultNullArgument;
	if (output) *output = control->pState;
	return PrynResultSuccess;
}

PrynGuiExport (PrynResult, prynGuiControlTags, (PrynGuiControl *control, PrynTagList **output))
{
	if (output) *output = 0;
	if (!control) return PrynResultNullArgument;
	if (output) *output = &control->pTags;
	return PrynResultSuccess;
}

PrynGuiExport (PrynResult, prynGuiReportError, (PrynState *state, PrynResult result))
{
	PrynGuiMessageBoxType type = PrynGuiMessageBoxTypeOkay;
	PrynResourceIndex caption, title;
	PrynString captionText, titleText;

	if (result < 0)
		type |= PrynGuiMessageBoxTypeIconError;
	
	if (result <= PrynResultMaximum && result >= PrynResultMinimum)
	{
		caption = prynResultCaptionIds + result;
		title = prynResultTitleIds + result;
	}
	else
	{
		caption = prynResultCaptionIds_Unknown;
		title = prynResultTitleIds_Unknown;
	}
	
	prynStateResourceString (state, caption, &captionText);
	prynStateResourceString (state, title, &titleText);

	result = prynGuiMessageBox (state, &titleText, &captionText, type);
	return result;
}

PrynGuiExport (PrynResult, prynGuiControlDirtyRectangle, (PrynGuiControl *control, const PrynRectangle *area))
{
	if (!area) return PrynResultNullArgument;
	return prynGuiControlDirtyArea (control, area->left, area->top, area->right, area->bottom);
}

